<?php

/**
 * Class AccountController
 */
class AdminController extends BaseController
{
    public function __construct(){
        parent::__construct();
//权限控制
        if (Session::has(UserEnum::ADMIN_USER_KEY)) {
            $admin_info = Session::get(UserEnum::ADMIN_USER_KEY);
            $action = Route::currentRouteAction();
            list($class, $method) = explode('@', $action);
//            $user_info->role_id = UserEnum::USER_ROLE_ADMINISTRATOR;
            $aMenus = AdminMenuEnum::getUserMenus($admin_info->role_id);
            //dd($method);
            if (!in_array($method, $aMenus)) {
                $page = AccountService::instance()->getDefaultPage($admin_info->role_id);
                echo "<script>alert('您的权限不够');location='/admin$page';</script>";
            }
        }else{
            $action = Route::currentRouteAction();
            list($class, $method) = explode('@', $action);
            if ($method == 'Login') {
                return Redirect::to("/admin/");
            }else if($method == 'DisposeLogin'){
                return Redirect::to("/admin/depose_login");
            }else if( $method == 'CacheCate'){
                return Redirect::to("/admin/cache_cate");
            }
        }
    }
    /**
     * 登录
     * @author  fyl
     */
    public function Login(){
        return $this->view('admin.login');
    }

    /**
     * 登录请求
     * @author  fyl
     */
    public function DisposeLogin()
    {
        #接受参数
        $paramObj                   =          new stdClass();
        $paramObj->username         =          $this->getParam('username');          //用户名
        $paramObj->password         =          $this->getParam('password');          //密码
        $paramObj->captcha          =          $this->getParam('captcha');           //验证码

        try{
            AdminService::instance()->LoginValidator($paramObj);
            return Redirect::to('/admin/manage_product');
        }catch (Exception $e){
            return Redirect::to('/admin');
        }
    }

    /**
     * 生成验证码
     * @author fyl
     * @date 2016-03-05
     */
    public function Captcha()
    {
        CaptchaService::instance()->create();
    }

    /**
     * 林场列表显示
     * @return mixed
     * @author  lizhongpeng
     * @date    2016-03-30
     */
    public function forest_service()
    {
        $info = AdminService::instance()->ShowForest();
        return $this->view('admin.forest_service')->with('info', $info);
    }

    /**
     * 林场列表删除
     */

    public function DeleteForest()
    {
        #收集信息
        $aData = new stdClass();
        $aData->id = $this->getParam('forest_id');
        $aData->video_id = $this->getParam('video_id');


        #逻辑操作
        $state = AdminService::instance()->DeleteForest($aData);
        #林场名称
        $forest_name = AdminService::instance()->GetForestInfo($aData->id)->forest_name;
        LogService::instance()->write(['content' => '删除林场'.$forest_name, 'type' => '林场服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 林场线路ajax返回模板
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function ForestServiceAjax()
    {
        $info = AdminService::instance()->ShowForest();
        //dd($info);die;
        return $this->viewAjax('admin.ajaxTemplates.forest_list_part')->with('info', $info);
    }

    /**
     * 林场列表编辑
     */
    public function EditForest()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj                       =          new stdClass();
            $paramObj->forest_id            =          $this->getParam('forest_id');            //林场id
            $paramObj->forest_name          =          $this->getParam('forest_name');          //林场名称
            $paramObj->country              =          $this->getParam('country');              //国家
            $paramObj->product_cate         =          $this->getParam('product_cate');         //品类
            $paramObj->type                 =          $this->getParam('type');                 //林场类型
            $paramObj->introduce            =          $this->getParam('introduce');            //简介
            $paramObj->show_pic1            =          $this->getParam('show_pic1');            //展示图1
            $paramObj->show_pic2            =          $this->getParam('show_pic2');            //展示图2
            $paramObj->show_pic3            =          $this->getParam('show_pic3');            //展示图3
            $paramObj->show_pic1_old        =          $this->getParam('show_pic1_old');        //展示图1
            $paramObj->show_pic2_old        =          $this->getParam('show_pic2_old');        //展示图2
            $paramObj->show_pic3_old        =          $this->getParam('show_pic3_old');        //展示图3



            #逻辑操作
            empty($paramObj->forest_id) ?
                (AdminService::instance()->AddForest($paramObj).
                    LogService::instance()->write(['content' => '添加林场'.$paramObj->forest_name, 'type' => '林场服务'])):
                (AdminService::instance()->EditForest($paramObj).
                    LogService::instance()->write(['content' => '修改林场'.$paramObj->forest_name, 'type' => '林场服务']));

            return Redirect::to('/admin');
        } else {
            $id = $this->getParam('forest_id');
            $info = AdminService::instance()->GetForestInfo($id);
            return $this->view('admin.forest_import')->with('forest', $info);

        }
    }

    /**
     * 林场录入
     * @return mixed
     * @author  lizhongpeng
     * @date    2016-03-30
     */

    public function ForestImport()
    {
        return $this->view('admin.forest_import');
    }

    /**
     * 物流线路列表显示
     * @return mixed
     * @author fyl
     * @date 2016-03-29
     */
    public function TransportService()
    {
        $info = AdminService::instance()->TransportList();

        return $this->view('admin.transport_service')->with('lists',$info);
    }

    /**
     * 物流线路录入
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function TransportModify()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->id = $this->getParam('id');
        if (!empty($paramObj->id)) {
            $info = AdminService::instance()->SelectOneTransport($paramObj);
            return $this->view('admin.transport_import')->with("info", $info);
        } else {
            return $this->view('admin.transport_import');
        }
    }

    /**
     * 物流线路修改
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function TransportUpdateAction()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->wl_id            =    $this->getParam('wl_id');
            $paramObj->departure        =    $this->getParam('departure');
            $paramObj->destination      =    $this->getParam('destination');
            $paramObj->model_type       =    $this->getParam('model_type');
            $paramObj->truck_length     =    $this->getParam('truck_length');
            $paramObj->truck_weight     =    $this->getParam('truck_weight');
            $paramObj->take_time        =    $this->getParam('d_time')."天".$this->getParam('h_time')."小时";
            $paramObj->spec_time        =    $this->getParam('spec_time');
            $paramObj->created          =    time();
            #逻辑处理
            try {
                AdminService::instance()->UpdateTransport($paramObj);
                LogService::instance()->write(['content' => '修改物流线路'.$paramObj->departure, 'type' => '物流服务']);
                return Redirect::to('/admin/transport_service');
            } catch (Exception $e) {
                $this->rest->error($e->getMessage(), $e->getCode());
            }
        }
    }

    /**
     * 物流线路删除
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function TransportDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->wl_id = $this->getParam('wl_id');
        $state = AdminService::instance()->DeleteOneTransport($paramObj);
        LogService::instance()->write(['content' => '删除物流线路'.$paramObj->wl_id, 'type' => '物流服务']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 物流线路ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function TransportServiceAjax()
    {
        $info = AdminService::instance()->TransportList();
        $this->viewAjax('admin.ajaxTemplates.transport_list_part')->with('lists',$info);
    }



    /**
     * 物流线路入库
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function TransportModifyAction()
    {
        if(Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->departure        =    $this->getParam('departure');
            $paramObj->destination      =    $this->getParam('destination');
            $paramObj->model_type       =    $this->getParam('model_type');
            $paramObj->truck_length     =    $this->getParam('truck_length');
            $paramObj->truck_weight     =    $this->getParam('truck_weight');
            $paramObj->take_time        =    $this->getParam('d_time')."天".$this->getParam('h_time')."小时";
            $paramObj->spec_time        =    $this->getParam('spec_time');
            $paramObj->created          =    time();
            #逻辑处理
            try {
                AdminService::instance()->AddTransport($paramObj);
                LogService::instance()->write(['content' => '增加物流线路'.$paramObj->departure, 'type' => '物流服务']);
                return Redirect::to('/admin/transport_service');
            } catch (Exception $e) {
                $this->rest->error($e->getMessage(), $e->getCode());
            }
        }
    }

    /**
     * 港口列表显示
     * @return mixed
     * @author fyl
     * @date 2016-03-31
     */
    public function HarbourServiceAction()
    {
        $info = AdminService::instance()->HarbourList();
        return $this->view('admin.harbour_service')->with("lists",$info);
    }

    /**
     * 港口录入
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function HarbourImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->id = $this->getParam('harbour_id');
        if(!empty($paramObj->id)){
            $info = AdminService::instance()->SelectOneHarbour($paramObj);
            return $this->view('admin.harbour_import')->with("harbour",$info);
        }else{
            return $this->view('admin.harbour_import');
        }
    }

    /**
     * 港口添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function HarbourModifyAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->harbour_name         =          $this->getParam('harbour_name');         //港口名称
            $paramObj->city                 =          $this->getParam('city');                 //城市
            $paramObj->address              =          $this->getParam('address');              //地址
            $paramObj->quote                =          $this->getParam('quote');                //港口報價
            $paramObj->show_pic1            =          $this->getParam('show_pic1');            //展示图1
            $paramObj->show_pic2            =          $this->getParam('show_pic2');            //展示图2
            $paramObj->show_pic3            =          $this->getParam('show_pic3');            //展示图3
            $paramObj->video                =          $this->getParam('video');                //视频
            $paramObj->introduce            =          $this->getParam('introduce');            //简介
            #逻辑操作
            AdminService::instance()->AddHarbour($paramObj);
            LogService::instance()->write(['content' => '增加港口'.$paramObj->harbour_name, 'type' => '港口服务']);
            return Redirect::to('/admin/harbour_service');
        }
    }

    /**
     * 港口信息修改
     * @author  fyl
     * @date    2016-04-01
     */
    public function HarbourUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->harbour_id           =          $this->getParam('harbour_id');           //港口ID
            $paramObj->harbour_name         =          $this->getParam('harbour_name');         //港口名称
            $paramObj->city                 =          $this->getParam('city');                 //城市
            $paramObj->address              =          $this->getParam('address');              //地址
            $paramObj->quote                =          $this->getParam('quote');                //港口報價
            $paramObj->show_pic1            =          $this->getParam('show_pic1');            //展示图1
            $paramObj->show_pic2            =          $this->getParam('show_pic2');            //展示图2
            $paramObj->show_pic3            =          $this->getParam('show_pic3');            //展示图3
            $paramObj->video                =          $this->getParam('video');                //视频
            $paramObj->introduce            =          $this->getParam('introduce');            //简介
            $paramObj->show_pic1_old        =          $this->getParam('show_pic1_old');        //展示图1
            $paramObj->show_pic2_old        =          $this->getParam('show_pic2_old');        //展示图2
            $paramObj->show_pic3_old        =          $this->getParam('show_pic3_old');        //展示图3
            #逻辑操作
            AdminService::instance()->UpdateHarbour($paramObj);
            LogService::instance()->write(['content' => '修改港口'.$paramObj->harbour_name, 'type' => '港口服务']);
            return Redirect::to('/admin/harbour_service');
        }
    }



    /**
     * 港口删除
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function HarbourDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->harbour_id = $this->getParam('harbour_id');
        $paramObj->id         = $this->getParam('harbour_id');

        //获取港口名称
        $harbour_name = AdminService::instance()->SelectOneHarbour($paramObj)->harbour_name;
        $state = AdminService::instance()->DeleteOneHarbour($paramObj);
        LogService::instance()->write(['content' => '删除港口'.$harbour_name, 'type' => '港口服务']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 港口ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function HarbourServiceAjax()
    {
        $info = AdminService::instance()->HarbourList();
        $this->viewAjax('admin.ajaxTemplates.harbour_list_part')->with('lists',$info);
    }


    /**
     * 資訊列表
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsList()
    {
        $info = AdminService::instance()->NewsList();
        return $this->view("admin.news_list")->with('lists',$info);
    }

    /**
     * 資訊录入
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->id = $this->getParam('zx_id');
        if(!empty($paramObj->id)){
            $info = AdminService::instance()->SelectOneNews($paramObj);
            return $this->view('admin.news_import')->with(["news"=>$info,"type"=>InformationEnum::$information_types]);
        }else{
            return $this->view('admin.news_import')->with('type',InformationEnum::$information_types);
        }
    }

    /**
     * 咨讯添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function NewsModifyAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->title                =          $this->getParam('title');
            $paramObj->author               =          $this->getParam('author');
            $paramObj->source               =          $this->getParam('source');
            $paramObj->keywords             =          $this->getParam('keywords');
            $paramObj->thumb_img1           =          $this->getParam('thumb_img1');
            $paramObj->thumb_img2           =          $this->getParam('thumb_img2');
            $paramObj->thumb_img3           =          $this->getParam('thumb_img3');
            $paramObj->cate                 =          $this->getParam('cate');
            $paramObj->content              =          $this->getParam('content');
            #逻辑操作
            AdminService::instance()->AddNews($paramObj);
            LogService::instance()->write(['content' => '添加资讯'.$paramObj->title, 'type' => '资讯管理']);
            return Redirect::to('/admin/news_list');
        }
    }

    /**
     * 资讯修改
     * @author  fyl
     * @date    2016-04-01
     */
    public function NewsUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->zx_id                =          $this->getParam('zx_id');
            $paramObj->title                =          $this->getParam('title');
            $paramObj->author               =          $this->getParam('author');
            $paramObj->source               =          $this->getParam('source');
            $paramObj->keywords             =          $this->getParam('keywords');
            $paramObj->thumb_img1           =          $this->getParam('thumb_img1');
            $paramObj->thumb_img2           =          $this->getParam('thumb_img2');
            $paramObj->thumb_img3           =          $this->getParam('thumb_img3');
            $paramObj->cate                 =          $this->getParam('cate');
            $paramObj->content              =          $this->getParam('content');
            $paramObj->thumb_img1_old        =          $this->getParam('thumb_img1_old');        //展示图1
            $paramObj->thumb_img2_old        =          $this->getParam('thumb_img2_old');        //展示图2
            $paramObj->thumb_img3_old        =          $this->getParam('thumb_img3_old');        //展示图3
            #逻辑操作
            AdminService::instance()->UpdateNews($paramObj);
            LogService::instance()->write(['content' => '修改资讯'.$paramObj->title, 'type' => '资讯管理']);
            return Redirect::to('/admin/news_list');
        }
    }



    /**
     * 資訊删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function NewsDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->zx_id = $this->getParam('zx_id');
        $state = AdminService::instance()->DeleteOneNews($paramObj);
        $title = AdminService::instance()->SelectOneNews($paramObj);
        LogService::instance()->write(['content' => '修改资讯'.$title->title, 'type' => '资讯管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 港口ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function NewsServiceAjax()
    {
        $info = AdminService::instance()->NewsList();
        $this->viewAjax('admin.ajaxTemplates.news_list_part')->with('lists',$info);
    }




    /**
     * 仓储服务
     * @return mixed
     * @author lizhongpeng
     * @date 2016-03-31
     */
    public function StorageService()
    {
        $info = AdminService::instance()->ShowStorage();
        return $this->view("admin.storage_service")->with('info',$info);
    }

    /**
     * 仓储录入
     * @return mixed
     * @author lizhongpeng
     * @date 2016-04-01
     */
    public function StorageImport()
    {
        return $this->view("admin.storage_import");
    }

    /**
     * 仓储添加编辑
     */
    public function StorageEdit()
    {
        if(Request::isMethod('POST'))
        {
            #收集信息
            $paramObj                        =          new stdClass();
            $paramObj->storage_id            =          $this->getParam('storage_id');            //仓储id
            $paramObj->storage_name          =          $this->getParam('storage_name');          //j基地名称
            $paramObj->storage_address       =          $this->getParam('storage_address');       //基地地址
            $paramObj->quote                 =          $this->getParam('quote');                 //基地报价
            $paramObj->introduce             =          $this->getParam('introduce');             //基地特色
            $paramObj->show_pic1             =          $this->getParam('show_pic1');              //展示图1
            $paramObj->show_pic2             =          $this->getParam('show_pic2');              //展示图2
            $paramObj->show_pic3             =          $this->getParam('show_pic3');              //展示图3
            $paramObj->show_pic1_old         =          $this->getParam('show_pic1_old');          //展示图1
            $paramObj->show_pic2_old         =          $this->getParam('show_pic2_old');          //展示图2
            $paramObj->show_pic3_old         =          $this->getParam('show_pic3_old');          //展示图3

            #逻辑操作
            empty($paramObj->storage_id) ?
                (AdminService::instance()->StorageAdd($paramObj).
                LogService::instance()->write(['content' => '添加仓储'.$paramObj->storage_name, 'type' => '仓促服务'])):
                (AdminService::instance()->StorageUp($paramObj).
                LogService::instance()->write(['content' => '修改仓储'.$paramObj->storage_name, 'type' => '仓促服务']));

            return Redirect::to('/admin/storage_service');
        }
        else
        {
            $id = $this->getParam('storage_id');
            $info = AdminService::instance()->GetStorageInfo($id);
            return $this->view('admin.storage_import')->with('storage',$info);

        }

    }

    /**
     * 仓储列表删除
     */
    public function StorageDelete()
    {
        #收集信息
        $aData              =     new stdClass();
        $aData->id          =     $this->getParam('storage_id');
        $aData->video_id    =     $this->getParam('video_id');

        #仓储名称
        $storage_name = AdminService::instance()->GetStorageInfo($aData->id)->storage_name;
        #逻辑操作
        $state = AdminService::instance()->StorageDelete($aData);
        LogService::instance()->write(['content' => '删除仓储'.$storage_name, 'type' => '仓促服务']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');

    }

    /**
     * 仓储线路ajax返回模板
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function StorageServiceAjax()
    {
        $info = AdminService::instance()->ShowStorage();
        return $this->viewAjax('admin.ajaxTemplates.storage_list_part')->with('info',$info);
    }



    /*----------------------------------------------产品----------------------------------------------*/
    /**
     * 产品列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ManageProduct(){
        $info = AdminService::instance()->ShowProduct();
        return $this->view('admin.manage_product')->with('product_list',$info);
    }

    /**
     * 审核列表
     * @return mixed
     * @author fyl
     * @date 2016-05-24
     */
    public function ProductExamineList(){
        $info = AdminService::instance()->ProductExamineList();
        return $this->view('admin.product_examine_list')->with('product_list',$info);
    }

    /**
     * 产品录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
        if(!empty($paramObj->product_id)){
            $info = AdminService::instance()->SelectOneProduct($paramObj);
          // $band  = AdminService::instance()->ShowProductBrand();
            $cate  = AdminService::instance()->ShowProductCateQuality();
           /*  $area  = AdminService::instance()->ShowProductArea();
            $spec  = AdminService::instance()->ShowProductSpec();
            $level = AdminService::instance()->ShowProductLevel();*/
            return $this->view('admin.product_import')->with(['product'=>$info,'cate'=>$cate]);
        }else{
          // $info  = AdminService::instance()->ShowProductBrand();
            $cate  = AdminService::instance()->ShowProductCateQuality();
            /* $area  = AdminService::instance()->ShowProductArea();
            $spec  = AdminService::instance()->ShowProductSpec();
            $level = AdminService::instance()->ShowProductLevel();*/
            $supplier = AdminService::instance()->SupplierInfo();
            return $this->view('admin.product_import')->with(['cate'=>$cate,'supplier'=>$supplier]);
        }
    }

    /**
     * 产品审核
     * @return mixed
     * @author fyl
     * @date 2016-05-24
     */
    public function ProductExamine()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
            $info = AdminService::instance()->SelectOneProduct($paramObj);
         /*     $band  = AdminService::instance()->ShowProductBrand();
           $cate  = AdminService::instance()->ShowProductCateQuality();
      /$area  = AdminService::instance()->ShowProductArea();
           $spec  = AdminService::instance()->ShowProductSpec();
           $level = AdminService::instance()->ShowProductLevel();*/
            return $this->view('admin.product_examine')->with('product',$info);

    }


    /**
     * 产品审核
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductExamineAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->product_id           =          $this->getParam('product_id');     //审核状态
            $paramObj->status               =          $this->getParam('status');     //审核状态
            $paramObj->examine              =          $this->getParam('examine');    //审核描述
            #逻辑操作
            AdminService::instance()->UpdateStatus($paramObj);
            LogService::instance()->write(['content' => '审核产品ID为'. $paramObj->product_id, 'type' => '产品管理']);
            return Redirect::to('/admin/manage_product');
        }
    }


    /**
     * 产品添加
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                          =          new stdClass();
            $paramObj->supplier_id             =          $this->getParam('supplier_id');   //所属商家
            $paramObj->product_name            =          $this->getParam('product_name');  //产品名称
            $paramObj->category                =          $this->getParam('category');      //品类
            $paramObj->classes                 =          $this->getParam('classes');       //材质
            $paramObj->stock                   =          $this->getParam('stock');         //库存
            $paramObj->unit                    =          $this->getParam('unit');          //单位
            $paramObj->price                   =          $this->getParam('price');         //价格
            $paramObj->description             =          $this->getParam('description');   //商品描述
            $paramObj->place                   =          $this->getParam('place');         //产地
            $paramObj->spec                    =          $this->getParam('spec');          //规格
            $paramObj->storage                 =          $this->getParam('storage');       //仓储地
            $paramObj->start_num               =          $this->getParam('start_num');     //起订量
            $paramObj->product_img             =          $this->getParam('product_img');   //展示图
            $paramObj->show_pic1               =          $this->getParam('show_pic1');     //展示图1
            $paramObj->show_pic2               =          $this->getParam('show_pic2');     //展示图2
           // dd($paramObj);
            #逻辑操作
            AdminService::instance()->AddProduct($paramObj);
            LogService::instance()->write(['content' => '产品添加'. $paramObj->product_name, 'type' => '产品管理']);
            return Redirect::to('/admin/manage_product');
        }
    }

    /**
     * 产品修改
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                          =          new stdClass();
            $paramObj->product_id              =          $this->getParam('product_id');
            $paramObj->supplier_id             =          $this->getParam('supplier_id');   //所属商家
            $paramObj->product_name            =          $this->getParam('product_name');  //产品名称
            $paramObj->category                =          $this->getParam('category');      //品类
            $paramObj->classes                 =          $this->getParam('classes');       //材质
            $paramObj->stock                   =          $this->getParam('stock');         //库存
            $paramObj->unit                    =          $this->getParam('unit');          //单位
            $paramObj->price                   =          $this->getParam('price');         //价格
            $paramObj->description             =          $this->getParam('description');   //商品描述
            $paramObj->place                   =          $this->getParam('place');         //产地
            $paramObj->spec                    =          $this->getParam('spec');          //规格
            $paramObj->storage                 =          $this->getParam('storage');       //仓储地
            $paramObj->start_num               =          $this->getParam('start_num');     //起订量
            $paramObj->product_img             =          $this->getParam('show_pic1');     //展示图
            $paramObj->show_pic1               =          $this->getParam('show_pic2');     //展示图1
            $paramObj->show_pic2               =          $this->getParam('show_pic3');     //展示图2
            $paramObj->product_img_old         =          $this->getParam('product_img1_old');     //展示图
            $paramObj->product_pic1_old        =          $this->getParam('product_img2_old');     //展示图1
            $paramObj->product_pic2_old        =          $this->getParam('product_img3_old');     //展示图2
            #逻辑操作
            AdminService::instance()->UpdateProduct($paramObj);
            LogService::instance()->write(['content' => '产品修改'. $paramObj->product_name, 'type' => '产品管理']);
            return Redirect::to('/admin/manage_product');
        }
    }


    /**
     * 产品删除
     * @return mixed
     * @author fyl
     * @date 2016-04-13
     */
    public function ProductDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->product_id = $this->getParam('product_id');
        $product_name = AdminService::instance()->SelectOneProduct($paramObj)->product_name;
        $state = AdminService::instance()->DeleteOneProduct($paramObj);
        LogService::instance()->write(['content' => '产品删除'. $product_name, 'type' => '产品管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 产品ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-03-30
     */
    public function ProductServiceAjax()
    {
        $info = AdminService::instance()->ShowProduct();
        $this->viewAjax('admin.ajaxTemplates.Product_list_part')->with('product_list',$info);
    }


    /**
     * 产品地区列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductPlace(){
        $info = AdminService::instance()->ShowProductArea();
        return $this->view('admin.product_place')->with('place',$info);
    }

    /**
     * 产品地区录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductPlaceImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->area_id = $this->getParam('area_id');
        if(!empty($paramObj->area_id)){
            $info = AdminService::instance()->SelectOneProductPlace($paramObj);
            return $this->view('admin.product_place_import')->with('place',$info);
        }else{
            return $this->view('admin.product_place_import');
        }
    }

    /**
     * 地区添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function ProductPlaceImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->area_name            =          $this->getParam('area_name');
            $paramObj->country              =          $this->getParam('country');
            #逻辑操作
            AdminService::instance()->AddProductPlace($paramObj);
            LogService::instance()->write(['content' => '地区添加'. $paramObj->area_name, 'type' => '地区管理']);
            return Redirect::to('/admin/product_place');
        }
    }

    /**
     * 地区修改
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductPlaceUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                      =          new stdClass();
            $paramObj->area_id             =          $this->getParam('area_id');
            $paramObj->area_name           =          $this->getParam('area_name');
            $paramObj->country             =          $this->getParam('country');
            #逻辑操作
            AdminService::instance()->UpdateProductPlace($paramObj);
            LogService::instance()->write(['content' => '地区修改'. $paramObj->area_name, 'type' => '地区管理']);
            return Redirect::to('/admin/product_place');
        }
    }

    /**
     * 地区删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductPlaceDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->area_id = $this->getParam('area_id');
        $place_name = AdminService::instance()->SelectOneProductPlace($paramObj)->area_name;
        $state = AdminService::instance()->DeleteOneProductArea($paramObj);
        LogService::instance()->write(['content' => '地区删除'. $place_name, 'type' => '地区管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 地区ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductPlaceAjax()
    {
        $info = AdminService::instance()->ShowProductArea();
        $this->viewAjax('admin.ajaxTemplates.product_area_part')->with('place',$info);
    }


    /**
     * 产品品牌列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductBrand(){
        $info = AdminService::instance()->ShowProductBrand();
        return $this->view('admin.product_brand')->with('brand',$info);
    }

    /**
     * 产品品牌录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductBrandImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->brand_id = $this->getParam('brand_id');
        if(!empty($paramObj->brand_id)){
            $info = AdminService::instance()->SelectOneProductBrand($paramObj);
            $cate = AdminService::instance()->ShowProductCateQuality();
            return $this->view('admin.product_brand_import')->with(['brand'=>$info,'quality'=>$cate]);
        }else{
            $info = AdminService::instance()->ShowProductCateQuality();
            return $this->view('admin.product_brand_import')->with('quality',$info);
        }
    }

    /**
     * 品牌添加
     * @author  fyl
     * @date    2016-03-31
     */
    public function ProductBrandImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->brand_name           =          $this->getParam('brand_name');
            $paramObj->quality              =          $this->getParam('quality');
            $paramObj->is_show              =          $this->getParam('is_show');
            $paramObj->brand_img            =          $this->getParam('brand_img');
            #逻辑操作
            AdminService::instance()->AddProductBrand($paramObj);
            LogService::instance()->write(['content' => '品牌添加'. $paramObj->brand_name, 'type' => '品牌管理']);
            return Redirect::to('/admin/product_brand');
        }
    }

    /**
     * 品牌修改
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductBrandUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->brand_id             =          $this->getParam('brand_id');
            $paramObj->brand_img            =          $this->getParam('brand_img');
            $paramObj->brand_name           =          $this->getParam('brand_name');
            $paramObj->quality              =          $this->getParam('quality');
            $paramObj->is_show              =          $this->getParam('is_show');
            $paramObj->brand_img_old        =          $this->getParam('brand_img_old');
            #逻辑操作
            AdminService::instance()->UpdateProductBrand($paramObj);
            LogService::instance()->write(['content' => '品牌修改'. $paramObj->brand_name, 'type' => '品牌管理']);
            return Redirect::to('/admin/product_brand');
        }
    }

    /**
     * 品牌删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductBrandDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->brand_id = $this->getParam('brand_id');
        $state = AdminService::instance()->DeleteOneProductBrand($paramObj);
        $brand = AdminService::instance()->SelectOneProductBrand($paramObj);
        LogService::instance()->write(['content' => '品牌删除'. $brand->brand_name, 'type' => '品牌管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 品牌ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductBrandAjax()
    {
        $info = AdminService::instance()->ShowProductBrand();
        $this->viewAjax('admin.ajaxTemplates.product_brand_part')->with('brand',$info);
    }



    /**
     * 产品分类列表
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductCate(){
        $info = AdminService::instance()->ShowProductCateAll();
        return $this->view('admin.product_cate')->with('cate',$info);
    }

    /**
     * 缓存产品分类列表
     * @return mixed
     * @author fyl
     * @date 2016-06-21
     */
    public function CacheCate(){
         AdminService::instance()->CacheCate();
    }

    /**
     * 产品类型录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductCateImport()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->cate_id = $this->getParam('cate_id');
        $paramObj->length = $this->getParam('length');
        if(!empty($paramObj->cate_id)){
            $info = AdminService::instance()->SelectOneProductCate($paramObj);
            if($paramObj->length == 1){
                return $this->view('admin.product_cate_import')->with('productcate',$info);
            }elseif($paramObj->length == 2){
                $c = AdminService::instance()->ShowProductCate();
                return $this->view('admin.product_class_import')->with(['cate'=>$c,'productcate'=>$info]);
            }elseif($paramObj->length == 3){
                $q = AdminService::instance()->ShowProductCateClasses();
                return $this->view('admin.product_quality_import')->with(['cate'=>$q,'productcate'=>$info]);
            }
        }else{
            return $this->view('admin.product_cate_import');
        }
    }

    /**
     * 分类，品类，材质修改
     * @author  fyl
     * @date    2016-04-05
     */
    public function ProductCateUpdateAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                       =          new stdClass();
            $paramObj->cate_id                  =          $this->getParam('cate_id');
            $paramObj->length                   =          $this->getParam('length');
            $paramObj->cate_name                =          $this->getParam('cate_name');
            $paramObj->parent_id                =          $this->getParam('parent_id');
            $paramObj->remark                   =          $this->getParam('remark');
            #逻辑操作
            AdminService::instance()->UpdateProductCate($paramObj);
            LogService::instance()->write(['content' => '分类，品类，材质修改'. $paramObj->cate_name, 'type' => '分类，品类，材质管理']);
            return Redirect::to('/admin/harbour_service');
        }
    }


    /**
     * 类型删除
     * @return mixed
     * @author fyl
     * @date 2016-04-01
     */
    public function ProductCateDeleteAction()
    {
        #接收参数
        $paramObj = new stdClass();
        $paramObj->cate_id = $this->getParam('cate_id');
        $state = AdminService::instance()->DeleteOneProductCate($paramObj);
        LogService::instance()->write(['content' => '分类，品类，材质修改'. $paramObj->cate_id , 'type' => '分类，品类，材质管理']);
        $this->rest->success(['state' => $state],ErrorCodeEnum::STATUS_SUCCESS,'刪除成功！');
    }

    /**
     * 类型ajax返回模板
     * @return mixed
     * @author fyl
     * @date 2016-04-05
     */
    public function ProductCateAjax()
    {
        $info = AdminService::instance()->ShowProductCateAll();
        $this->viewAjax('admin.ajaxTemplates.product_cate_part')->with('cate',$info);
    }



    /**
     * 产品规格录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductSpecImport()
    {
        $cate = AdminService::instance()->ShowProductCateQuality();
        return $this->view('admin.product_spec_import')->with('quality',$cate);
    }

    /**
     * 规格入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductSpecImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->spec_name                =          $this->getParam('spec_name');
            $paramObj->quality                   =          $this->getParam('quality');
            $paramObj->sort_by                   =          $this->getParam('sort_by');
            #逻辑操作
            AdminService::instance()->AddProductSpec($paramObj);
            LogService::instance()->write(['content' => '规格添加'. $paramObj->spec_name , 'type' => '规格管理']);
            return Redirect::to('/admin/product_spec_import');
        }
    }

    /**
     * 产品等级录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductLevelImport()
    {
        $cate = AdminService::instance()->ShowProductCateQuality();
        return $this->view('admin.product_level_import')->with('quality',$cate);
    }

    /**
     * 等级入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductLevelImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                            =          new stdClass();
            $paramObj->level_name                =          $this->getParam('level_name');
            $paramObj->quality                   =          $this->getParam('quality');
            $paramObj->sort_by                   =          $this->getParam('sort_by');
            #逻辑操作
            AdminService::instance()->AddProductLevel($paramObj);
            LogService::instance()->write(['content' => '等级添加'.$paramObj->level_name , 'type' => '等级管理']);
            return Redirect::to('/admin/product_level_import');
        }
    }

    /**
     * 产品材质录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductQualityImport()
    {
        $info = AdminService::instance()->ShowProductCateClasses();
        return $this->view('admin.product_quality_import')->with('classes',$info);
    }


    /**
     * 材质入库
     * @author  fyl
     * @date    2016-04-04
     */
    public function ProductQualityImportAction()
    {
        #接收参数
        if(Request::isMethod('POST'))
        {
            $paramObj                           =          new stdClass();
            $paramObj->length                   =          $this->getParam('length');
            $paramObj->cate_name                =          $this->getParam('cate_name');
            $paramObj->parent_id                =          $this->getParam('parent_id');
            $paramObj->remark                   =          $this->getParam('remark');
            #逻辑操作
            AdminService::instance()->AddProductCate($paramObj);
            LogService::instance()->write(['content' => '材料添加'. $paramObj->cate_name , 'type' => '材料管理']);
            return Redirect::to('/admin/product_quality_import');
        }
    }

    /**
     * 产品品类录入
     * @return mixed
     * @author fyl
     * @date 2016-04-04
     */
    public function ProductClassImport()
    {
        $info = AdminService::instance()->ShowProductCate();
        return $this->view('admin.product_class_import')->with('cate',$info);
    }


    /**
     * 文章
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function ArticleList()
    {
        $info = AdminService::instance()->ArticleList();
        return $this->view('admin.article_list')->with('info', $info);
    }

    /**
     * 文章删除
     */
    public function ArticleDelete()
    {
        #收集信息
        $aData = new stdClass();
        $aData->id = $this->getParam('help_id');

        $title = AdminService::instance()->GetArticleId($aData->id)->title;
        #逻辑操作
        $state = AdminService::instance()->ArticleDelete($aData);
        LogService::instance()->write(['content' => '删除文章'.$title, 'type' => '文章服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     *  文章ajax返回模板
     */
    public function ArticleServiceAjax()
    {
        $info = AdminService::instance()->ArticleList();
        return $this->viewAjax('admin.ajaxTemplates.article_list_part')->with('info', $info);
    }

    /**
     * 文章录入
     */
    public function ArticleImport()
    {
        return $this->view("admin.article_import");
    }

    /**
     * 文章编辑
     */
    public function ArticleEdit()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj           = new stdClass();
            $paramObj->help_id  = $this->getParam('help_id');         //文章id
            $paramObj->title    = $this->getParam('title');           //文章标题
            $paramObj->content  = $this->getParam('content');         //文章内容
            $paramObj->type     = $this->getParam('type');            //文章类型

            #逻辑操作
            empty($paramObj->help_id) ?
                (AdminService::instance()->ArticleAdd($paramObj).
                LogService::instance()->write(['content' => '添加文章'.$paramObj->title, 'type' => '文章服务'])):
                (AdminService::instance()->ArticleUp($paramObj).
                LogService::instance()->write(['content' => '修改文章'.$paramObj->title, 'type' => '文章服务']));
            return Redirect::to('/admin/article_show');
        } else {
            $id = $this->getParam('help_id');
            $info = AdminService::instance()->GetArticleId($id);
            return $this->view('admin.article_import')->with('article', $info);

        }

    }

    /**
     * 会员
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function ManageCustomer()
    {
        $info = AdminService::instance()->ManagerUser();
        return $this->view('admin.manage_customer')->with('info', $info);
    }

    /**
     * 马甲列表
     * @return mixed
     */
    public function MajiaList()
    {
        //$info=AdminService::instance()->MajiaList();
        return $this->view('admin.majia_list');
    }

    /**
     * 会员录入
     * @return mixed
     */
    public function CustomerImport()
    {
        return $this->view('admin.customer_import');
    }

    /**
     * 会员编辑
     * @return mixed
     */
    public function CustomerEdit()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->user_id          =   $this->getParam('user_id');          //ID
            $paramObj->user_name        =   $this->getParam('user_name');        //姓名
            $paramObj->password         =   $this->getParam('password');         //密码
            $paramObj->mobile           =   $this->getParam('mobile');           //手机号
            $paramObj->avatar           =   $this->getParam('avatar');           //头像
            $paramObj->corporation      =   $this->getParam('corporation');      //公司名称

            //#逻辑操作
            empty($paramObj->user_id) ?
                (AdminService::instance()->CustomerAdd($paramObj).
                    LogService::instance()->write(['content' => '添加会员'.$paramObj->user_name, 'type' => '会员服务'])):
                (AdminService::instance()->CustomerUp($paramObj).
                    LogService::instance()->write(['content' => '修改会员'.$paramObj->user_name, 'type' => '会员服务']));
            return Redirect::to('/admin/manage_customer');
        } else {
            $id = $this->getParam('user_id');
            $info = AdminService::instance()->GetUserInfo($id);
            return $this->view('admin.customer_import')->with('user', $info);
        }


    }

    /**
     * 会员删除
     */
    public function CustomerDelete()
    {
        #收集信息
        $aData = new stdClass();
        $aData->user_id = $this->getParam('user_id');

        #逻辑操作
        $state = AdminService::instance()->CustomerDelete($aData);
        $user_name = AdminService::instance()->GetUserInfo($aData->user_id)->title;
        LogService::instance()->write(['content' => '删除会员'.$user_name, 'type' => '会员服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 会员ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-01
     */
    public function CustomerServiceAjax()
    {
        $info = AdminService::instance()->ManagerUser();
        //dd($info);die;
        return $this->viewAjax('admin.ajaxTemplates.user_list_part')->with('info', $info);
    }

    /**
     * 管理员管理
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function ManageAdmin()
    {
        $info = AdminService::instance()->ManageAdmin();
        return $this->view('admin.manage_admin')->with('info', $info);
    }

    /**
     * 管理员添加
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function AddAdmin()
    {
        return $this->view('admin.add_admin');
    }

    /**
     * 管理员编辑
     * @return mixed
     */
    public function EditAdmin()
    {

        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj             = new stdClass();
            $paramObj->id         = $this->getParam('id');                 //ID
            $paramObj->name       = $this->getParam('name');               //姓名
            $paramObj->real_name  = $this->getParam('real_name');          //真名
            $paramObj->password   = $this->getParam('password');           //密码
            $paramObj->role_id    = $this->getParam('role_id');            //角色
            $paramObj->mobile     = $this->getParam('mobile');             //联系方式
            $paramObj->avatar     = $this->getParam('avatar');             //头像
            $paramObj->status     = $this->getParam('status');             //状态
            $paramObj->sure       = $this->getParam('sure');               //密码确认
            $paramObj->avatar_old = $this->getParam('avatar_old');


            #逻辑处理
            empty($paramObj->id) ?
                (AdminService::instance()->AdminAdd($paramObj).
                    LogService::instance()->write(['content' => '添加管理员'.$paramObj->name, 'type' => '管理员管理'])):
                (AdminService::instance()->AdminUp($paramObj).
                    LogService::instance()->write(['content' => '修改管理员'.$paramObj->name, 'type' => '管理员管理']));
            return Redirect::to('/admin/manage_admin');
        } else {
            $id = $this->getParam('id');
            $info = AdminService::instance()->GetAdminInfo($id);
            return $this->view('admin.add_admin')->with('admin', $info);
        }
    }

    /**
     * 管理员删除
     */
    public function DeleteAdmin()
    {
        #收集信息
        $aData = new stdClass();
        $aData->id = $this->getParam('id');

        $name = AdminService::instance()->GetAdminInfo($aData->id)->name;
        #逻辑操作
        $state = AdminService::instance()->DeleteAdmin($aData);
        LogService::instance()->write(['content' => '删除管理员'.$name, 'type' => '管理员管理']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }

    /**
     * 管理员删除ajax返回
     */
    public function AdminServiceAjax()
    {
        $info = AdminService::instance()->ManageAdmin();
        return $this->viewAjax('admin.ajaxTemplates.admin_list_part')->with('info', $info);
    }


    /**
     * 日志
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function LogService()
    {
        $info = AdminService::instance()->LogService();
        return $this->view('admin.log_service')->with('info',$info);
    }
    /**
     *日志删除
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function DeleteLog()
    {
        #收集信息
        $aData = new stdClass();
        $aData->log_id         =   $this->getParam('log_id');


        #逻辑操作
        $state = AdminService::instance()->DeleteLog($aData);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }
    /**
     * 日志ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-04
     */
    public function LogServiceAjax()
    {
        $info = AdminService::instance()->LogService();
        return $this->viewAjax('admin.ajaxTemplates.log_list_part')->with('info', $info);
    }
    /**
     * 商家管理
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function ManageSupplier()
    {
        $info = AdminService::instance()->ManageSupplier();
        return $this->view('admin.manage_supplier')->with('info',$info);
    }
    /**
     * 商家入驻
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function AddSupplier()
    {
        $user = AdminService::instance()->UserSelect();
        return $this->view('admin.add_supplier')->with('user',$user);
    }
    /**
     * 编辑商家
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function EditSupplier()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj                            =          new stdClass();
            $paramObj->supplier_id               =          $this->getParam('supplier_id');            //供应商id
            $paramObj->user_id                   =          $this->getParam('user_id');                //入驻会员ID
            $paramObj->supplier_name             =          $this->getParam('supplier_name');          //供应商名称
            $paramObj->company                   =          $this->getParam('company');                //公司名称
            $paramObj->address                   =          $this->getParam('address');                //地址
            $paramObj->address_all                   =          $this->getParam('address_all');            //详细地址
            $paramObj->phone                     =          $this->getParam('phone');                  //联系方式
            $paramObj->operate_license           =          $this->getParam('operate_license');        //营业执照
            $paramObj->show_img1                 =          $this->getParam('show_img1');              //商家展示图1
            $paramObj->show_img2                 =          $this->getParam('show_img2');              //商家展示图2
            $paramObj->show_img3                 =          $this->getParam('show_img3');              //商家展示图3
            $paramObj->operate_license_old       =          $this->getParam('operate_license_old');    //营业执照
            $paramObj->tax_license_old           =          $this->getParam('tax_license_old');        //税务登记证
            $paramObj->show_img1_old             =          $this->getParam('show_img1_old');          //商家展示图1
            $paramObj->show_img2_old             =          $this->getParam('show_img2_old');          //商家展示图2
            $paramObj->show_img3_old             =          $this->getParam('show_img3_old');          //商家展示图3
            #逻辑操作
            empty($paramObj->supplier_id) ?
                (AdminService::instance()->SupplierAdd($paramObj).
                    LogService::instance()->write(['content' => '添加商家'.$paramObj->supplier_name , 'type' => '商家服务'])):
                (AdminService::instance()->SupplierUp($paramObj).
                    LogService::instance()->write(['content' => '修改商家'.$paramObj->supplier_name , 'type' => '商家服务']));
            return Redirect::to('/admin/manage_supplier');
        } else {
            $supplier_id = $this->getParam('supplier_id');
            $info = AdminService::instance()->GeSupplierId($supplier_id);
            return $this->view('admin.add_supplier')->with('supplier', $info);
        }
    }
    /**
     * 删除商家
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
     public function DelSupplier()
     {
         #收集信息
         $aData = new stdClass();
         $aData->supplier_id      =   $this->getParam('supplier_id');

         $supplier_name = AdminService::instance()->GeSupplierId($aData->supplier_id)->supplier_name;
         #逻辑操作
         $state = AdminService::instance()->DelSupplier($aData);
         LogService::instance()->write(['content' => '删除商家'.$supplier_name, 'type' => '商家服务']);
         $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
     }
    /**
     * 商家ajax返回
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function SupplierAjax()
    {
        $info = AdminService::instance()->ManageSupplier();
        return $this->viewAjax('admin.ajaxTemplates.supplier_list_part')->with('info', $info);
    }

    /**
     *订单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function OrderList()
    {
        $info = AdminService::instance()->OrderList();

        return $this->view('admin.order_listings')->with('info',$info);

    }
    /**
     *询价单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function InquiryList()
    {
        $info = AdminService::instance()->InquiryList();
        return $this->view('admin.inquiry_listings')->with('info',$info);

    }
    /**
     *定制单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function CustomizeList()
    {
        $info = AdminService::instance()->CustomizeList();
        return $this->view('admin.customize_listings')->with('info',$info);

    }

    /**
     *查看定制单
     * @return mixed
     * @author fyl
     * @date 2016-06-01
     */
    public function CustomizeStatus()
    {
        $aData = new stdClass();
        $aData->customize_id   =   $this->getParam('customize_id');
        $info = AdminService::instance()->CustomizeOne($aData);
        return $this->view('admin.customize_status')->with('info',$info);

    }

    /**
     *修改定制单状态
     * @return mixed
     * @author fyl
     * @date 2016-06-01
     */
    public function CustomizeUpdate()
    {
        $aData = new stdClass();
        $aData->customize_id   =   $this->getParam('customize_id');
        $aData->status         =   $this->getParam('status');
        AdminService::instance()->CustomizeUpdate($aData);
        LogService::instance()->write(['content' => '修改ID为'.$aData->customize_id.'定制单状态', 'type' => '订单管理']);
        return Redirect::to('/admin/customize_list');

    }


    /**
     *供货单列表
     * @return mixed
     * @author lzhp
     * @date 2016-04-05
     */
    public function SupplyList()
    {
        $info = AdminService::instance()->SupplyList();
        return $this->view('admin.supply_listings')->with('info',$info);

    }

    /**
     * 广告位列表
     * @return mixed
     */
    public function AdsList()
    {
        $info = AdminService::instance()->AdsList();
        return $this->view('admin.ads_list')->with('info',$info);
    }

    /**
     * 广告位录入
     * @return mixed
     */
    public function AddAds()
    {
        return $this->view('admin.add_ads');
    }

    /**
     * 广告位编辑
     * @return mixed
     */
    public function EditAds()
    {
        if (Request::isMethod('POST')) {
            #收集信息
            $paramObj = new stdClass();
            $paramObj->ads_id           = $this->getParam('ads_id');            //广告id
            $paramObj->ads_name         = $this->getParam('ads_name');          //广告名称
            $paramObj->img              = $this->getParam('img');               //图片
            $paramObj->img_old          = $this->getParam('img_old');           //图片
            $paramObj->type             = $this->getParam('type');              //广告类型
            $paramObj->is_rec           = $this->getParam('is_rec');            //是否推荐
            $paramObj->order_by         = $this->getParam('order_by');          //排序
            $paramObj->link             = $this->getParam('link');              //链接

            #逻辑操作
            empty($paramObj->ads_id) ?
                (AdminService::instance()->AdsAdd($paramObj).
                 LogService::instance()->write(['content' => '广告位添加'.$paramObj->ads_name, 'type' => '广告位服务'])):
                (AdminService::instance()->AdsUp($paramObj).
                    LogService::instance()->write(['content' => '广告位修改'.$paramObj->ads_name, 'type' => '广告位服务']));
            return Redirect::to('/admin/ads_list');
        } else {
            $ads_id = $this->getParam('ads_id');
            $info = AdminService::instance()->GetAdsInfo($ads_id);
            return $this->view('admin.add_ads')->with('ads', $info);

        }
    }

    /**
     * 广告位删除
     */
    public function DelAds()
    {
        #收集信息
        $aData = new stdClass();
        $aData->ads_id = $this->getParam('ads_id');

        $ads_name = AdminService::instance()->GetAdsInfo($aData->ads_id)->ads_name;
        #逻辑操作
        $state = AdminService::instance()->DelAds($aData);
        LogService::instance()->write(['content' => '广告位删除'.$ads_name, 'type' => '广告位服务']);
        $this->rest->success(['state' => $state], ErrorCodeEnum::STATUS_SUCCESS, '刪除成功！');
    }
    public function AdsAjax()
    {
        $info = AdminService::instance()->AdsAjax();
        return $this->viewAjax('admin.ajaxTemplates.ads_list_part')->with('info', $info);
    }


    /**
     *林场直供
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function ForestNeed()
    {
        $info = AdminService::instance()->ForestNeed();
        return $this->view('admin.forest_need')->with('info',$info);

    }

    /**
     *港口需求
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function HarbourNeed()
    {
        $info = AdminService::instance()->HarbourNeed();
        return $this->view('admin.harbour_need')->with('info',$info);

    }

    /**
     *仓储需求
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function StorageNeed()
    {
        $info = AdminService::instance()->StorageNeed();
        return $this->view('admin.storage_need')->with('info',$info);

    }


}





